package com.teatang.tadmin.sysrole.service;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.teatang.tadmin.core.page.PageDataReturn;
import com.teatang.tadmin.sysrole.mapper.SysRoleMapper;
import com.teatang.tadmin.sysrole.pojo.SysRole;
import com.teatang.tadmin.sysrole.pojo.SysRoleSearch;
import com.teatang.tadmin.util.PageUtils;
import com.teatang.tadmin.util.ServletUtils;
import com.teatang.tadmin.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysRoleServiceImpl implements SysRoleService{
    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public PageDataReturn getSysRolePageData() {
        String searchParamsStr = ServletUtils.getParameter("searchParams", "");
        SysRoleSearch sysRoleSearch = new SysRoleSearch();
        if(!StringUtils.isEmpty(searchParamsStr)) {
            sysRoleSearch = JSON.parseObject(searchParamsStr, SysRoleSearch.class);
        }
        List<SysRole> sysRolePageList = sysRoleMapper.getSysRolePageList(sysRoleSearch);

        return PageUtils.getDataPage(sysRolePageList, new PageInfo(sysRolePageList).getTotal());
    }
}
